package com.gitee.wsl.ext.any

inline fun <reified T, reified R> T.mapTo(
    transform: (map: T) -> R
): R = transform(this)

inline fun <reified T> Any?.castTo(): T {
    @Suppress("UNCHECKED_CAST")
    return this as T
}

inline fun <reified T> Any?.castToOrNull(): T? {
    @Suppress("UNCHECKED_CAST")
    return this as? T
}

inline infix fun <reified T>  Any?.then(callBack:(Any)->T):T?{
    if(this!=null) return callBack(this)
    return null
}

inline fun <reified T : Any> Any?.ifType(block: (T) -> Unit) {
    if (this is T) block(this)
}